package com.maple.common.ext


import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction

/**
 * Tip:Fragment 拓展函数
 * Create by SeVen on 2023/7/19 10:09
 */
inline fun FragmentManager.inTransaction(func: FragmentTransaction.() -> FragmentTransaction) {
    beginTransaction().func().commit()
}

fun FragmentActivity.addFragment(fragment: Fragment, containerViewId: Int) {
    supportFragmentManager.inTransaction { add(containerViewId, fragment) }
}


fun FragmentActivity.replaceFragment(fragment: Fragment, containerViewId: Int) {
    supportFragmentManager.inTransaction { replace(containerViewId, fragment) }
}

fun FragmentActivity.replaceFragment(fragment: Fragment, containerViewId: Int, tag: String) {
    supportFragmentManager.inTransaction { replace(containerViewId, fragment, tag) }
}

fun FragmentActivity.getFragmentTag(tag: String): Fragment? {
    return supportFragmentManager.findFragmentByTag(tag)
}

fun FragmentActivity.removeFragment(fragment: Fragment) {
    supportFragmentManager.inTransaction { remove(fragment) }
}

fun FragmentActivity.showFragment(fragment: Fragment) {
    supportFragmentManager.inTransaction { show(fragment) }
}

fun FragmentActivity.hideFragment(fragment: Fragment) {
    supportFragmentManager.inTransaction { hide(fragment) }
}





